// +build !windows

package utils

import (
	"gin-bms/core"
	"os"
	"path"
	"time"

	rotatelogs "github.com/lestrrat-go/file-rotatelogs"
	"go.uber.org/zap/zapcore"
)

/**
 * @description: GetWriteSyncer
 * @function: GetWriteSyncer
 * @param {*}
 * @return {*}
 */
func GetWriteSyncer() (zapcore.WriteSyncer, error) {
	fileWriter, err := rotatelogs.New(
		path.Join(core.GLOBAL_CONFIG.Zap.Director, "%Y-%m-%d.log"),
		rotatelogs.WithLinkName(core.GLOBAL_CONFIG.Zap.LinkName),
		rotatelogs.WithMaxAge(7*24*time.Hour),
		rotatelogs.WithRotationTime(24*time.Hour),
	)
	if core.GLOBAL_CONFIG.Zap.LogInConsole {
		return zapcore.NewMultiWriteSyncer(zapcore.AddSync(os.Stdout), zapcore.AddSync(fileWriter)), err
	}
	return zapcore.AddSync(fileWriter), err
}
